package com.yh.spring.mybatis.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import com.yh.spring.mybatis.model.User;

public class LoginInterceptor extends MethodFilterInterceptor {
	private static Logger logger=LogManager.getLogger(LoginInterceptor.class);
	private static final long serialVersionUID = 1L;
	@Override
	protected String doIntercept(ActionInvocation invocation) throws Exception {
		ActionContext ctx = invocation.getInvocationContext();
		Map<String, Object> session = ctx.getSession();
		//User user = (User) session.get("userSession");
		if (session.get("userSession") != null) {
			return invocation.invoke();
		} else {
			HttpServletResponse response = ServletActionContext.getResponse();
			response.getWriter().print(-1);
			return null;
		}
	}
}
